<template>
  <div class="empty-box">
    <div class="top">
      <img src="../../assets/images/login/logo.png" />
    </div>

    <div class="info-box">
      <div class="people">
        <div class="item">
          <div class="left">申请人</div>
          <div class="right">{{deliveryInfo.userName}}</div>
        </div>
      </div>

      <div class="info">
        <div class="item">
          <div class="left">配送人员</div>
          <div class="right">{{workerName}}</div>
        </div>
        <div class="item">
          <div class="left">配送日期</div>
          <div class="right">{{deliveryInfo.deliveryOn}}</div>
        </div>
        <div class="item">
          <div class="left">配送数量</div>
          <div class="right">{{deliveryInfo.boxAmount}}</div>
        </div>
        <div class="item">
          <div class="left">配送地址</div>
          <div class="right">{{deliveryInfo.address}}</div>
        </div>
      </div>
      <div class="btn" v-if="deliveryInfo.status === 1">
          <div class="submit" @click="submit">
              <span>签 收</span>
          </div>
      </div>
    </div>
  </div>
</template>

<script>
import { os } from "@/utils/common.js";
import {
  getOrderDetail,
  orderExecute
} from "@/api/access-manage/index";
export default {
  // 申请空窍申请
  name: "applyEmptyConfirm",
  data() {
    return {
      info: {},
      workerName: '',
      deliveryInfo: {}
    };
  },
  mounted() {
    this.info = this.$route.query;
    this.workerName = this.info.workerName

    // ?id=415&workerName=宋卫奇
    this.getOrderInfo()
  },
  methods: {
    // 获得订单信息
    getOrderInfo() {
      new Promise((resolve) => {
        getOrderDetail(this.info.id).then(res => {
          this.deliveryInfo ={
            deliveryOn: res.data?.deliveryOn &&
                    this.$moment(res.data.deliveryOn * 1000).format(
                      "YYYY-MM-DD HH:mm:ss"
                    ),
            address: res.data.address,
            boxAmount: res.data.orderDemandAttrBean?.boxAmount,
            userName: res.data.userName,
            status: res.data.status
          }
        })

      })

    },
    submit() {
      const data = {}
      const params ={
        id: this.info.id
      };
      new Promise((resolve) => {
        orderExecute(data, params).then(res => {
          if (res.code === 200) {
            this.$message.success('订单已签收')
            this.getOrderInfo()
            // 如果不是在手机上 则不需要返回
            if(!(os.isAndroid || os.isPhone)) {
              this.$router.back()
            }
          }
        })
      })
    },
  },
};
</script>

<style lang="scss" scoped>
.empty-box {
  padding: 10px;
  background-color: #f5f5f5;
  height: 100vh;
  max-width: 500px;
  margin: 0 auto;
  .top {
    line-height: 35px;
    // background-color: #f88123;
    color: #fff;
    text-align: center;
    border-radius: 10px 10px 0 0;
  }
    .info-box {
        .people, .info {
            background-color: #fff;
            padding: 12px 15px;
            margin: 20px 0 ;
            border-radius: 10px;
            line-height: 32px;
            font-size: 16px;
        }
        .item {
            display: flex;
            .left {
                width: 30%;
                // text-align: right;
            }
            .right {
                width: 70%;
                text-align: right;
            }
        };

        .btn {
            display: flex;
            justify-content: center;
            margin-top: 30px;
            .submit {
                cursor: pointer;
                width: 70%;
                height: 40px;
                line-height: 40px;
                font-size: 16px;
                color: #fff;
                background-color: #f88123;
                text-align: center;
                border-radius: 20px;
            }
        }
    }
}
</style>
